from tests.new_rypark_background.get_cookie import *


class RentRule:
    # =====================商家停车后台=====================
    # 新建规则
    def create_rule(self, env, rentType, ruleName,
                    rentUnitType, rentAmount, saleChannel, payAmount,
                    partitionStart, partitionEnd, includeHoliday, weekLimit):
        base_url = getconf(env, "zhongtai_url")
        url = base_url + "platform-parking-order-server/rule/rent/add"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "token": internal_token(env)}
        dict = {
            "rentType": rentType,
            "ruleName": ruleName,
            "rentUnitType": rentUnitType,
            "rentAmount": rentAmount,
            "saleChannel": saleChannel,
            "payAmount": payAmount,
            "comment": "自动化生成长租规则",
            "partitionStart": partitionStart,
            "partitionEnd": partitionEnd,
            "includeHoliday": includeHoliday,
            "weekLimit": weekLimit
        }
        return requests.post(url, headers=headers, json=dict).json()

    # 规则列表查询
    def query_rule_list(self, env, rentType="", saleChannel="", status="", current="1", size="10"):
        base_url = getconf(env, "zhongtai_url")
        url = base_url + "platform-parking-order-server/rule/rent/getPageList?rentType=" \
              + rentType + "&saleChannel=" + saleChannel + "&status =" + status + "&current=" + current + "&size=" + size
        headers = {"content-type": "application/json;charset=UTF-8",
                   "token": internal_token(env)}
        return requests.get(url, headers=headers).json()

    # 编辑规则
    def update_rule(self, env, dict):
        base_url = getconf(env, "zhongtai_url")
        url = base_url + "platform-parking-order-server/rule/rent/update"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "token": internal_token(env)}
        return requests.post(url, headers=headers, json=dict).json()

    # 禁用规则
    def update_rule_status(self, env, dict):
        base_url = getconf(env, "zhongtai_url")
        url = base_url + "platform-parking-order-server/rule/rent/updateStatus"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "token": internal_token(env)}
        dict = {
            "id": dict['id'],
            "status": 2
        }
        return requests.post(url, headers=headers, json=dict).json()

    # 删除规则
    def delete_rule(self, env, dict):
        base_url = getconf(env, "zhongtai_url")
        url = base_url + "platform-parking-order-server/rule/rent/delete"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "token": internal_token(env)}
        dict = {
            "id": dict['id']
        }
        return requests.post(url, headers=headers, json=dict).json()

    # 获取当前后台登录账号创建branchId
    def get_branchid(self, env):
        return account_branchid(env)
